package com.imooc.web.controller;

import com.imooc.web.DistributeLock;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class DistributedLockAspect {

	@Pointcut("@annotation(Lock)")
	private void pointCutMethod() {};

	@Autowired
	DistributeLock distributeLock;

	@Around(value = "pointCutMethod()")
	public Object around(final ProceedingJoinPoint pjp) throws Throwable {
		distributeLock.getLock();
		Object proceed = pjp.proceed();
		distributeLock.releaseLock();
		return proceed;
	}
}
